#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "mypushbutton.h"
#include <QPainter>
#include <QTimer>
#include <QSound>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //设置固定大小
    setFixedSize(320,588);

    //设置图标
    setWindowIcon(QIcon(":/res/Coin0001.png"));

    setWindowTitle("翻金币主场景");

    //退出
    connect(ui->actionquit, &QAction::triggered, [=](){
        this->close();
    });

    //开始音效
    QSound * startSound = new QSound(":/res/TapButtonSound.wav",this);



    //开始按钮
    MyPushButton * startBtn = new MyPushButton(":/res/MenuSceneStartButton.png");
    startBtn->setParent(this);

    startBtn->move(this->width()*0.5 - startBtn->width()*0.5, this->height() * 0.7);

    chooseLevel = new ChooseLevelScene(this);
    //this->chooseLevel->setGeometry(this->geometry());
    //弹跳效果
    connect(startBtn, &MyPushButton::clicked, [=](){

       startSound->play();
       startBtn->zoomBottom();
       startBtn->zoomTop();

       //延时
        QTimer::singleShot(500, this, [=](){
            this->hide();
            chooseLevel->show();


        });


    });

    connect(chooseLevel, &ChooseLevelScene::chooseSceneBack, [=](){
        this->setGeometry(chooseLevel->geometry());
        this->show();
        chooseLevel->hide();
    });
}

void MainWindow::paintEvent(QPaintEvent*)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/res/OtherSceneBg.png");
    painter.drawPixmap(0, 0,this->width(), this->height(), pix);

    //图标
    pix.load(":/res/Title.png");
    pix = pix.scaled(pix.width()*0.5, pix.height()*0.5);
    painter.drawPixmap(10, 30, pix);
}

MainWindow::~MainWindow()
{
    delete ui;
}
